package com.hamster.common.puremvc.mediator
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class BaseMediator extends Mediator
	{
		public function BaseMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			var handler:String = getNotiHandlerName(name);
			
			if (this.hasOwnProperty(handler)) {
				var func:Function = this[handler];
				func.apply(this, [body]);
			} else {
				trace (this.mediatorName + ":" + name + "received but no handler found!");
			}
			
		}
		
		public function getNotiHandlerName(notiName:String):String
		{
			return "handle" + notiName.substr(0, 1).toLocaleUpperCase() + notiName.substr(1);
		}
	}
}